home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / music / cthugha5.zip / CTHU5SRC.ZIP / TRANSLAT.C < prev    next >
C/C++ Source or Header  |  1994-08-19  |  3KB  |  139 lines

  1. //
  2. // Cthugha - Audio Seeded Image Processing
  3. //
  4. // Zaph, Digital Aasvogel Group, Torps Productions 1993-1994
  5. //
  6.  
  7.  
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <io.h>
  11. #include <fcntl.h>
  12. #include <stdlib.h>
  13. #include <math.h>
  14. #include <conio.h>
  15. #include <bios.h>
  16. #include <memory.h>
  17. #include <assert.h>
  18.  
  19. #include "cthugha.h"
  20. #include "charset.h"
  21. #include "zorilkey.h"
  22. #include "audio.h"
  23. #include "translat.h"
  24.  
  25. static unsigned char tempscrn[BUFF_SIZE];
  26.  
  27. // Use two half-sized tables because MSC can then optimize the code
  28. // to be almost TWICE as fast (no >64k blocks)
  29. static unsigned int mapping1[102][BUFF_WIDTH];
  30. static unsigned int mapping2[102][BUFF_WIDTH];
  31.  
  32. static int have_table=0;
  33.  
  34. void translate_screen(void)
  35. {
  36.     register unsigned int x;
  37.     register char *screen;
  38.     register unsigned int *map;
  39.  
  40.     if (!have_table)
  41.         return;
  42.  
  43.     screen=buff;
  44.     map=mapping1;
  45.  
  46.     memcpy(tempscrn,buff,BUFF_SIZE);
  47.  
  48.     tempscrn[0]=0;  // Set 0,0 to black - for safety reasons :-)
  49.  
  50.     for (x=0; x<(102*BUFF_WIDTH); x++) {
  51.         *screen++=tempscrn[*map++];
  52.     }
  53.  
  54.     map=mapping2;
  55.  
  56.     for (x=0; x<(102*BUFF_WIDTH); x++) {
  57.         *screen++=tempscrn[*map++];
  58.     }
  59.  
  60. }
  61.  
  62.  
  63. // int translate=1;
  64. int translate=0;
  65.  
  66. #define M_PI 3.14159265358979323846
  67. #define RADEG (180.0/M_PI)
  68. char maptabfile[255]="ROTATE.TAB";
  69.  
  70. int init_translate(void)
  71. {
  72.     int x,y,map_x,map_y;
  73.     double polar_r,polar_a;
  74.     double temp_y,temp_x;
  75.     unsigned int offset=0;
  76.     int badfile=0;
  77.  
  78.     FILE *fp;
  79.  
  80.     for (y=0; y<102; y++)
  81.         for (x=0; x<BUFF_WIDTH; x++)  {
  82.             mapping1[y][x]=0;
  83.             mapping2[y][x]=0;
  84.         }
  85.  
  86.     if ((fp=fopen(maptabfile,"rb"))!=NULL) {
  87.         printf("Reading translation table: %s\n",maptabfile);
  88.         printf("\nTranslation tables can be very slow on a 386...\n");
  89.         printf("To disable translation tables, rename the ROTATE.TAB file\n");
  90.  
  91.         for (y=0; y<102; y++) {
  92.             fread(&mapping1[y],sizeof(unsigned int),BUFF_WIDTH,fp);
  93.         }
  94.         for (y=0; y<102; y++) {
  95.             fread(&mapping2[y],sizeof(unsigned int),BUFF_WIDTH,fp);
  96.         }
  97.         fclose(fp);
  98.         for (y=0; y<102; y++)
  99.             for (x=0; x<BUFF_WIDTH; x++) {
  100.                 if (mapping1[y][x]<0) {
  101.                     printf("Neg at %d,%d\n",x,y);
  102.                     mapping1[y][x]=0;
  103.                     badfile++;
  104.                 }
  105.  
  106.                 if (mapping2[y][x]>=(unsigned int)BUFF_SIZE) {
  107.                     printf("High at %d,%d\n",x,y);
  108.                     mapping2[y][x]=0;
  109.                     badfile++;
  110.                 }
  111.                 if (mapping2[y][x]<0) {
  112.                     printf("Neg at %d,%d\n",x,y);
  113.                     mapping2[y][x]=0;
  114.                     badfile++;
  115.                 }
  116.  
  117.                 if (mapping2[y][x]>=(unsigned int)BUFF_SIZE) {
  118.                     printf("High at %d,%d\n",x,y);
  119.                     mapping2[y][x]=0;
  120.                     badfile++;
  121.                 }
  122.  
  123.             }
  124.         have_table=1;
  125.  
  126.         if (badfile)
  127.             printf("%d Errors in translation table\n",badfile);
  128.  
  129.         return 0;
  130.     } else {
  131.         printf("No Translation tables\n");
  132.         have_table=0;
  133.         return 1;
  134.     }
  135.  
  136. }
  137.  
  138.  
  139.